package com.dyb.recuitment;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.io.IOException;

/*项目启动类*/
@SpringBootApplication
@MapperScan("com.dyb.recuitment.mapper") // 扫描 mapper包

public class RecuitmentApplication {

    public static void main(String[] args) {

        // 启动项目,获取启动的应用
        ConfigurableApplicationContext application = SpringApplication.run(RecuitmentApplication.class, args);

        // 获取应用系统环境变量
        Environment env = application.getEnvironment();

        // 获取application.yml文档设置的端口(port)
        int port = Integer.parseInt(env.getProperty("server.port"));

        // 获取application.yml文档设置的上下文路径(context-path)
        String context = env.getProperty("server.servlet.context-path");

        // 如果context-path配置为"/"，则context为空字符串
        context = !context.equals("/") ? context : ""; // context = context.equals("/") ? "" : context;

        // 设置初始化页面的url地址
        String url = "http://localhost:" + port + context + "/doc.html";

        // 控制是否自动打开页面
        String open = env.getProperty("server.auto-open");
        if (open.equals("1")) {
            try {
                // 打开网页
                Runtime.getRuntime().exec("cmd /c start " + url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
